<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/taglibs.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<jsp:include page="/WEB-INF/jsp/common/include_easyui.jsp"></jsp:include>

<script type="text/javascript">



$(function(){
	
	var editUserId = $("#user_id").val();
	
	//加载部门列表
	$('#select_department').combobox({    
	    url:'<%=path%>/userMgrController/loadDepartmentList',    
	    valueField:		'id',   
	    textField:		'text'  ,
	    label:			'所属部门：',
	    required:		true,
	    labelAlign:		'right' ,
	    editable:		false,
		labelPosition: 	'left'

	});
	
	//加载职称列表
	$('#select_jobTitle').combobox({    
	    url:'<%=path%>/userMgrController/loadJobTitleList',    
	    valueField:		'id',   
	    label:			'职称：',
	    required:		true,
	    labelAlign:		'right' ,
	    textField:		'text'  ,
	    editable:		false,
		labelPosition: 	'left'

	});
	
	//加载角色列表信息
	$('#select_roleIds').combogrid({    
	    url:'<%=path%>/userMgrController/loadUserRoleList?userId='+editUserId+"",    
	    labelAlign:			'right' ,
		multiple: 			true,
		editable:			false,
		checkOnSelect:		true,
		selectOnCheck:		true,
		idField: 			'roleId',
		textField: 			'roleName',
		method: 			'get',
		columns: [[
			{field:'checkedId',	checkbox:true},   
	        {field:'roleId',		title:'角色ID',	width:60 ,halign:"center",align:"center"},    
	        {field:'roleName',	title:'角色名称',	width:150,halign:"center",align:"center"},    
	        {field:"roleRemark",	title:'角色备注',	width:200,halign:"left",align:"left"}    
		]],
		separator: 			"，",
		label:				'角色分配：',
		labelPosition: 		'left',
		onLoadSuccess: function(data){
			/* //alert(data.rows[0].roleId)
			var allRows = $("#select_roleIds").combogrid("grid").datagrid('getRows');
			//alert(allRows[0].roleId)
			
			var idArray = new Array();
			for(var idx = 0;idx<allRows.length;idx++){
				if(allRows[idx].selected){
					idArray.push(allRows[idx].roleId);
				}
			} */
			
			
			//数据加载完成后，回填用户拥有的角色
			$('#select_roleIds').combogrid('setValues',data.userRoleIdList );
		}

	});
	
});

function saveData(){
	
	$("#select_roleIds").combogrid('hidePanel');
	var isValid = jQuery("#modifyForm").form('validate');
	if(!isValid){
		jQuery("#modifyForm").form('enableValidation');
	}else{
		/* //获取选中的所有的角色ID
		var selectRoleIds = $("#select_roleIds").combogrid('getValues');
		//alert(selectRoleIds.length)
		var roleIds = selectRoleIds.join(",");
		//alert(roleIds)
		//存放入隐藏域中
		$("#roleIds").val(roleIds);
		 */

		var saveURL = "<%=path%>/userMgrController/modifyUser?date="+new Date()+"";
		var paramObj = jQuery("#modifyForm").serializeArray();

		//alert(jQuery("#modifyForm").serialize())

		jQuery.post(saveURL,paramObj,function(responseData){
			
			var code = responseData.code;
			if (code == "200"){
				$.messager.alert('我的消息','用户信息修改成功！','info', function(){
					var parentWin = window.parent;
					parentWin.jQuery("#div_table").datagrid("reload");
					parentWin.jQuery('#dialog_div').dialog("close");
				});

			}else{
				$.messager.alert('我的消息',"数据保存出错，原因 ：" + responseData.message,'error');
			}
			
		},"json");
	}
	
}
</script>

<style type="text/css">


.modify-form div{
	margin-bottom:20px;
/* 	display: flex;
    justify-content:center; */
}
	

.modify-form div input{
	max-width: 400px;
	height:26px;
	width:100%;
}
.modify-form .radioSpan{

      position: relative;
      border: 1px solid #95B8E7;
      background-color: #fff;
      display: inline-block;
      overflow: hidden;
      white-space: nowrap;
      margin: 0;
      padding: 0;
      -moz-border-radius: 5px 5px 5px 5px;
      -webkit-border-radius: 5px 5px 5px 5px;
      border-radius: 5px 5px 5px 5px;
      display:block;
} 
.modify-form .radioSpan input{
	max-width: 30px;
	height:20px;
	margin-top: 8px;
	margin-left: 20px;
}
.modify-form .radioSpan span{
	  width:80px; 
	  display: inline-block;
}
</style>
  </head>
  
  <body>
		<form:form commandName="user" id="modifyForm" method="post" class="modify-form">
			<div style="padding-left:12%;margin-top:20px;width: 80%;">
				<form:input class="easyui-textbox" path="userId" id="user_id" labelAlign="right" 
					data-options="label:'用户ID：',required:true,readonly:true"></form:input>
			</div>
			<div style="padding-left:12%;margin-top:20px;width: 80%;">
				<form:input class="easyui-textbox" path="userAccount" labelAlign="right" 
					data-options="label:'用户账号：',required:true,readonly:true"></form:input>
			</div>
			<div style="padding-left:12%;margin-top:20px;width: 80%;">
				<form:input class="easyui-textbox" path="name" labelAlign="right" 
					data-options="label:'用户姓名：',required:true"></form:input>
			</div>
			
			<div style="padding-left:12%;margin-top:20px;width: 80%;">
				<form:input path="department.id" id="select_department"></form:input>
			</div>
			<div style="padding-left:12%;margin-top:20px;width: 80%;">
				<form:input path="jobTitle.id" id="select_jobTitle"></form:input>
			</div>
			
			<div style="padding-left:12%;margin-top:20px;width: 80%;">
				<input name="selectRoleIds" id="select_roleIds">
				<!-- <input type="hidden" name="roleIds" id="roleIds"> -->
			</div>
			
			
			<!-- 可选 -->
			<div style="padding-left:12%;width: 80%;">
				<label class="textbox-label textbox-label-before" for="sex" 
					style="text-align: right; height: 36px; line-height: 36px;">性别：</label>
				<div class="radioSpan" style="width: 61%;height: 34px; line-height: 34px;float: right;margin-right: 22%; ">
					<span><form:radiobutton path="sex" value="1"></form:radiobutton>男</span>
	                <span><form:radiobutton path="sex" value="2"></form:radiobutton>女</span>
	                <span><form:radiobutton path="sex" value="0"></form:radiobutton>保密</span>
	            </div>
	        </div>
	        
			<div style="padding-left:12%;width: 80%;">
				<label class="textbox-label textbox-label-before" for="sex" 
					style="text-align: right; height: 36px; line-height: 36px;">婚姻状况：</label>
				<div class="radioSpan" style="width: 61%;height: 34px; line-height: 34px;float: right;margin-right: 22%; ">
					<span><form:radiobutton path="maritalStatus" value="1"></form:radiobutton>已婚</span>
	                <span><form:radiobutton path="maritalStatus" value="2"></form:radiobutton>未婚</span>
	                <span><form:radiobutton path="maritalStatus" value="0"></form:radiobutton>保密</span>
	            </div>
	        </div>
			
			<div style="padding-left:12%;margin-top:20px;width: 80%;">
				<form:input class="easyui-textbox" path="officeTel" labelAlign="right" data-options="label:'办公号码：'"></form:input>
			</div>
			<div style="padding-left:12%;margin-top:20px;width: 80%;">
				<form:input class="easyui-textbox" path="phone" labelAlign="right" data-options="label:'电话：'"></form:input>
			</div>
			<div style="padding-left:12%;margin-top:20px;width: 80%;">
				<form:input class="easyui-textbox" path="email" labelAlign="right" data-options="label:'邮箱：'"></form:input>
			</div>
			<div style="padding-left:12%;margin-top:20px;width: 80%;">
				<form:input class="easyui-textbox" path="idCardNo" labelAlign="right" data-options="label:'身份证号：'"></form:input>
			</div>
			<div style="padding-left:12%;width: 80%;">
				<form:input class="easyui-textbox" path="nativePlace" labelAlign="right" data-options="label:'籍贯：'"></form:input>
			</div>
			<div style="padding-left:12%;width: 80%;">
				<form:input class="easyui-textbox" path="address" labelAlign="right" data-options="label:'住址：'"></form:input>
			</div>
			<!-- 可选 -->
			
		</form:form>

  </body>
</html>
